//
//  UIButton+Property.m
//  RiceBasket
//
//  Created by DwZeng on 2021/1/15.
//

#import "UIButton+Property.h"

@implementation UIButton (Property)


+(UIButton* (^)())init{
    return ^(){
        UIButton *view = [[self alloc] init];
        return view;
    };
}

+(UIButton *(^)(CGRect frame))initFrame{
    return ^(CGRect frame){
        UIButton *view = [[self alloc] initWithFrame:frame];
        return view;
    };
}

+(UIButton* (^)(UIButtonType type))initType{
    return ^(UIButtonType type){
        return [self buttonWithType:type];
    };
}

-(UIButton *(^)(NSString *color))bgColor{
    return ^(NSString *color){
        self.backgroundColor = [UIColor colorWithHexString:color];
        return self;
    };
}

-(UIButton *(^)(NSString *, UIControlState))title{
    return ^(NSString *title,UIControlState state){
        [self setTitle:title forState:state];
        return self;
    };
}

-(UIButton *(^)(CGFloat))titleFont{
    return ^(CGFloat font){
        self.titleLabel.font = [UIFont fontOfSize:font];
        return self;
    };
}

-(UIButton *(^)(NSString *, UIControlState))titleColor{
    return ^(NSString *color,UIControlState state){
        [self setTitleColor:[UIColor colorWithHexString:color] forState:state];
        return self;
    };
}

-(UIButton *(^)(UIImage *, UIControlState))image{
    return ^(UIImage *image,UIControlState state){
        [self setImage:image forState:state];
        return self;
    };
}

-(UIButton *(^)(UIImage *, UIControlState))bgImage{
    return ^(UIImage *image,UIControlState state){
        [self setBackgroundImage:image forState:state];
        return self;
    };
}

-(UIButton *(^)(id, SEL, UIControlEvents))addTarget{
    return ^(id target,SEL selector,UIControlEvents event){
        [self addTarget:target action:selector forControlEvents:event];
        return self;
    };
}

-(UIButton *(^)(CGRect))setFrame{
    return ^(CGRect frame){
        self.frame = frame;
        return self;
    };
}


//快速创建bottomButton
+(UIButton *)bottomButton:(CGRect)frame Title:(NSString *)title Font:(CGFloat)font{
    UIButton *button = UIButton.initType(UIButtonTypeCustom).setFrame(frame).title(title,UIControlStateNormal).bgColor(@"ff2064").titleFont(font).titleColor(@"ffffff",UIControlStateNormal);
    button.layer.cornerRadius = button.height/2;
    return button;
}

//快速创建带边框button
+(UIButton *)borderButton:(CGRect)frame Title:(NSString *)title Font:(CGFloat)font color:(NSString *)color{
    UIButton *button = UIButton.initType(UIButtonTypeCustom).setFrame(frame).title(title,UIControlStateNormal).titleFont(font).titleColor(color,UIControlStateNormal);
    button.layer.borderColor = KSDColor(color).CGColor;
    button.layer.borderWidth = 1;
    button.layer.cornerRadius = button.height/2;
    return button;
}

@end
